package cn.yunhe.servlet;

import cn.yunhe.bean.Scenery;
import cn.yunhe.bean.Travel;
import cn.yunhe.biz.SceneryService;
import cn.yunhe.biz.TravelService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/SowMapServlet")
public class SowMapServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*获得轮播图上所需的景点图片*/
        SceneryService sceneryService = new SceneryService();
        List<Scenery> sceneryList = sceneryService.getAllRecommendScenery();
        request.setAttribute("sceneryList",sceneryList);

        /*获得旅游度假表格显示景点图片*/
        String string = request.getParameter("param");
//        System.out.println(string);
        if(string!=null){
            Integer param = Integer.parseInt(string);
            List<Scenery> sceneries = sceneryService.getSceneryByRecommend(param);
            request.setAttribute("sceneries",sceneries);
        }
        /*获得人气排行景点*/
        List<Scenery> sceList = sceneryService.getPopularityIndex();
        request.setAttribute("sceList",sceList);
        /*获得精品游记*/
        TravelService travelService = new TravelService();
        List<Travel> travelList=travelService.getExcellentTravel();
        request.setAttribute("travelList",travelList);

        request.getRequestDispatcher("main.jsp").forward(request,response);
    }
}
